<?php
require_once '../../include/common.inc.php';

$str = '';
$ctime = '';

$rid = $_REQUEST['rid']?$_REQUEST['rid']:1;
$total = $_REQUEST['total']?$_REQUEST['total']:50;
$nt = $_REQUEST['nt']?$_REQUEST['nt']:0;

//用户组
$query=$db->query("select * from {$tablepre}auth_group order by ov desc");
while($row=$db->fetch_row($query)){
    $groupli.="<div id='group_{$row[id]}'></div>";
    $grouparr.="grouparr['{$row[id]}']=".json_encode($row).";\n";
    $group["m".$row[id]]=$row;
}

$sql ="select * from {$tablepre}msgs where rid='".$rid."' and p='false' and state!='1' and `type`='0' and mtime <  ".$nt."   order by id desc limit 0, ".$total;

$query=$db->query($sql);
$result  = array();

//while($row=$db->fetch_row($query)){
////    $str =  '<img src="'.$row['ico'].'" alt="" />';
////    $ctime = $row['ctime'].' '.date_week($row['week']);
//    $result[]=$row;
//}

while($row=$db->fetch_row($query)){
    $row['msg']=str_replace(array('&amp;', '','&quot;', '&lt;', '&gt;'), array('&', "\'",'"', '<', '>'),$row['msg']);

    $time = date('Y-m-d H:i:s',$row[mtime]);
//    $nowDay  = date('m-d',time());
//    $time  = $day==$nowDay?date('H:i:s',$row[mtime]):date('m-d H:i:s',$row[mtime]);
    if($row[tuid]!="ALL"){
        $omsg="<div style='clear:both;'></div><div class='msg'  id='{$row[msgid]}'><div class='msg_head'><img src='../face/img.php?t=p1&u={$row[uid]}'></div><div class='msg_content'><div><font class='u'  onclick='ToUser.set(\"{$row[uid]}\",\"{$row[uname]}\")'>{$row[uname]}</font> <img src='".$group["m".$row[ugid]][ico]."' class='msg_group_ico' title='".$group["m".$row[ugid]][title]."-".$group["m".$row[ugid]][sn]."'>   <font class='dui'>对</font> <font class='u' onclick='ToUser.set(\"{$row[tuid]}\",\"{$row[tname]}\")'>{$row[tname]}</font> 说 <font class='date'>".$time."</font></div><div class='layim_chatsay' style='margin:5px 0px;'><font  style='{$row[style]};'>{$row[msg]}</font><em class='layim_zero'></em></div></div></div><div style='clear:both;'></div>".$omsg;
    }
    else{
        $omsg="<div style='clear:both;'></div><div class='msg' id='{$row[msgid]}'><div class='msg_head'><img src='../face/img.php?t=p1&u={$row[uid]}'></div><div class='msg_content'><div><font class='u'  onclick='ToUser.set(\"{$row[uid]}\",\"{$row[uname]}\")'>{$row[uname]}</font> <img src='".$group["m".$row[ugid]][ico]."' class='msg_group_ico' title='".$group["m".$row[ugid]][title]."-".$group["m".$row[ugid]][sn]."'> <font class='date'>".$time."</font></div><div class='layim_chatsay' style='margin:5px 0px;'><font  style='{$row[style]};'>{$row[msg]}</font><em class='layim_zero'></em></div></div></div><div style='clear:both;'></div>".$omsg;
    }
}

echo json_encode($omsg);

?>